<%-- 
    Document   : getStopsNear
    Created on : Aug 10, 2009, 5:22:45 PM
    Author     : david
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"
        import="com.appspot.nnaplanner.*,
        java.util.List,
        com.appspot.nnaplanner.DAL.*,
        java.util.logging.Logger
        "%>
<%
            float lat = 0;
            float lon = 0;
            float offset = 0;
            try {
                lat = 0 + Float.parseFloat(request.getParameter("lat"));
                lon = 0 + Float.parseFloat(request.getParameter("lon"));
                offset = 0 + Float.parseFloat(request.getParameter("offset"));
            } catch (Exception ex) {
                out.print("{\"total\":\"0\", \"msg\":\"Error: Wrong parameters\"}");
                return;
            }

            List<DALStop> results = Utils.getStopsNear(lat, lon, offset);
            Logger log = Logger.getLogger(this.getServletInfo());
            //log.info("lat: " + lat + ", lon: " + lon + ", offset: " + offset + ", total: " + results.size());
            out.print("{\"total\":\"" + results.size() + "\", \"stops\":[");
            int count = 0;
            for (DALStop s : results) {
                if (count > 0) {
                    out.print(", ");
                }
                out.print("{");
                out.print("\"stopid\": \"" + s.getID() + "\", ");
                out.print("\"name\": \"" + s.getName() + "\", ");
                out.print("\"description\": \"" + s.getDescription() + "\", ");
                out.print("\"latitude\": \"" + s.getLatitude() + "\", ");
                out.print("\"longitude\": \"" + s.getLongitude() + "\", ");
                out.print("\"connected\": \"" + s.isConnected() + "\"");
                out.print("}");
                count++;
            }
            out.print("] }");
%>